import { Component, OnInit } from '@angular/core';
import { StorageService } from '../../services/storage.service'
@Component({
  selector: 'app-todolist',
  templateUrl: './todolist.component.html',
  styleUrls: ['./todolist.component.less']
})
export class TodolistComponent implements OnInit {
  keyWord:string = ""
  public doing:any = []
  constructor(public storage:StorageService) { 
  }
  ngOnInit(): void {
    this.doing = this.storage.get('todo')
  }
  // 添加
  toAdd(e){
    if(e.keyCode == 13){
      if(this.keyWord.length==0){
        return
      }
      this.doing.push({
        thing: this.keyWord,
        status: false
      })
      this.storage.set('todo', this.doing)
      this.keyWord = ''
    }
  }
  // 删除
  toDel(index){
    this.doing.splice(index, 1)
    this.storage.set('todo', this.doing)
  }
  // 选中选项框触发的事件
  toOver(sta,index){
    this.storage.set('todo', this.doing)   
  }

}
